//
//  SettingVC.m
//  Meum
//
//  Created by 黄卫 on 17/2/27.
//  Copyright © 2017年 huangwei. All rights reserved.
//

#import "SettingVC.h"
#import "CommonAddressVC.h"
#import "AboutUsVC.h"
@interface SettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@end

@implementation SettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = Color_BackGround;
    [self.view addSubview:self.tableView];
    [self addCancelButton];
    NSLog(@"%f----%f",self.tableView.frame.origin.x,self.tableView.frame.origin.y);
}

-(UITableView *)tableView{
    if (!_tableView) {
        if (!_tableView) {
            _tableView = [UITableView groupedTableView];
            _tableView.frame = CGRectMake(0, 64, Screen_Width, 300);
            _tableView.scrollEnabled = NO;
        }
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

-(void)addCancelButton{
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat x = ([UIScreen mainScreen].bounds.size.width - 300)/2;
    cancelBtn.backgroundColor = [UIColor orangeColor];
    cancelBtn.frame = CGRectMake(x, CGRectGetMaxY(self.tableView.frame)+30, 300, 44);
    [cancelBtn setTitle:@"退出" forState:UIControlStateNormal];
    [self.view addSubview:cancelBtn];
}


#pragma mark UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return 1;
    }else{
        return 2;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = @"新消息通知";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.section==0) {
        UISwitch *sw = [[UISwitch alloc] init];
        cell.accessoryView  = sw;
        [sw setOn:YES];
    }
    
    return cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
    if (section==0) {
        return @"关闭或开启新消息通知，请在iphone“设置－通知中心－觅我“中更改";
    }
    return @"";
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section==1&&indexPath.row==0) {
        CommonAddressVC *addVc = [[CommonAddressVC alloc] init];
        [self.navigationController pushViewController:addVc animated:YES];
    } else if(indexPath.section==1&&indexPath.row==1) {
        AboutUsVC *aboutVc = [[AboutUsVC alloc] init];
        [self.navigationController pushViewController:aboutVc animated:YES];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
